<!-- 套餐详情 -->
<template>
	<view style="background: #F7F8FA;">
		<view class="Narbar">
			
			<view class="Narbar_bo"  :style="{ marginTop: heightConfig.navBarPaddingTop + 'px' }">
				<view @click="back"><u-icon name="arrow-left"></u-icon></view>
				<view class="title" size="19px">套餐详情</view>
				<view></view>
			</view>
			<view class="box">
				<view class="list">
					<view class="one">
						<image :src="baseImgUrl+exanmeData.imagePath[0]" style="
                              margin:16rpx 0 0 10rpx;width: 193rpx;
                               height: 150rpx;"></image>
					</view>
					<view class="two" style="margin-left:20rpx;">
						<view class="center1">
							{{exanmeData.setMealName}}
						</view>
						<view class="center2">
							{{exanmeData.subscribeMedicalExamType.description}}
						</view>
					</view>
					<view class="three">
						<view class="right2" style="margin-top: 10rpx;">
							<view class="text">x{{number}}</view>
						</view>
						<!-- <view class="right1">¥172.50</view> -->
					</view>
				</view>
				<view class="coseBox" style="">
					<view class="coseFle" style="">
						<view class="cose">
							费用
						</view>
						<view class="coseDet" style="margin:0 18rpx 0 0;">
							¥{{exanmeData.price * number}}
						</view>
					</view>
					<view class="border">
					</view>
					<view class="coseFle" style="">

						<view class="cose1">
							支付方式
						</view>
						<view class="coseImg">
							<image src="/static/images2/微信支付.png" mode=""></image>
						</view>
						<view class="coseDet1" style="margin:0 18rpx 0 0;">
							微信支付
						</view>
					</view>
				</view>
				<view class="buttonClick">
					<view class="buttonPay">
						<view class="pay1">
							付款金额:
						</view>
						<view class="pay2">
							￥{{exanmeData.price* number}}
						</view>
					</view>
					<view class="payPre" @click="payMent">
						<view class="button">
							支付并预约
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import integralApi from "@/api/integral";
	import order from "@/api/order.js"
	import {
		getToken
	} from "@/utils/auth";
	import {
		formatBigNumber
	} from "@/utils/index";
	import {
		baseImgUrl
	} from "@/config";
	import userApi from "@/api/user";
  
	export default {
		data() {
			return {
				tiJianLIst: [],
				baseImgUrl,
				heightConfig: {},
				creditScore: 0,
				remainingSum: 0,
				goodId: null,
				dataList: [],
				number:1,
				exanmeData: {},
				memberUserInfo: {},
				url:"",
				gridList: [{
						image: "../static/images/myPoints/pointsMall/getPoints.png",
						name: "获取积分",
						url: "/subPages/mine/myPoints",
					},
					{
						image: "../static/images/myPoints/pointsMall/PointsInfo.png",
						name: "积分明细",
						url: "/subPages/mine/integralDetail",
					},
					// {
					//   image: "../static/images/myPoints/pointsMall/PointsRule.png",
					//   name: "积分规则",
					//   url: "",
					// },
				],
			};
		},
		onLoad(optsions) {
			let _this = this
			uni.getSystemInfo({
			
				success(res) {
					_this.heightConfig.navBarPaddingTop = res.statusBarHeight // 单位：px
					console.log(res.statusBarHeight)
				}
			})
			
			console.log(optsions, "查询参数")
			const data = JSON.parse(decodeURIComponent(optsions.data));
			this.exanmeData = data
			this.number = this.exanmeData.number
			console.log(data)
		},
		onShow() {
			const token = getToken();
			if (!token) {
				uni.navigateTo({
					// url: "/pages/login",
				});
				return;
			}
			this.getIntegralGoodList();
			this.getUserInfo();
		},
		methods: {
			async payMent() {
				const params = {
					itemType: 0,
					projectId: this.exanmeData.id,
					number: this.number
				}
			
				//创建订单
				console.log(this.exanmeData)
				console.log("创建订单参数",params)
				const res = await order.createOrder(params)
				console.log(res, "创建订单")
				//支付订单
						const orderData = await order.orderPay({
							orderNo: res.data.orderNo,
							uuid:res.data.uuid,
						})

					//发起微信支付
					let _this = this
					wx.requestPayment({
						timeStamp: orderData.data.timeStamp,
						nonceStr: orderData.data.nonceStr,
						package: orderData.data.package,
						signType: orderData.data.signType,
						paySign: orderData.data.paySign,
						
						success: function(e) {
							//跳转到待预约填写界面
							_this.$u.toast("支付成功!")
							uni.navigateTo({
							   url:"/subPages/waitAppointment/waitAppointment",
							 })
						},
						fail: function(e) {
							console.log("失败");
							_this.$u.toast("取消支付!")
						}
					})
				
				// uni.navigateTo({
				//     url: "/pages/orderReservation/orderReservation/orderReservation",
				// })
			},
			back() {
				uni.navigateBack({
					delta: 1, //返回层数，2则上上页
				})
			},
			// 获取用户信息
			getUserInfo() {
				userApi.fetchUserInfo().then((res) => {
					if (res.code == 200) {
						this.memberUserInfo = res.memberUserInfo;
					}
				});
			},
			getList(pageNum, pageSize) {
				integralApi
					.getIntegralGoodList()
					.then((res) => {
						if (res.code == 200) {
							// this.creditScore = formatBigNumber(res.data.creditScore);
							this.creditScore = res.data.creditScore;
							this.remainingSum = formatBigNumber(res.data.remainingSum);
							this.$refs.paging.complete(res.data.appletBdmIntegralGoodVos);
						}
					})
					.catch(() => {
						this.$refs.paging.complete(false);
					});
			},
			getIntegralGoodList() {
				integralApi.getIntegralGoodList().then((res) => {
					if (res.code == 200) {
						// this.creditScore = formatBigNumber(res.data.creditScore);
						this.creditScore = res.data.creditScore;
						this.remainingSum = formatBigNumber(res.data.remainingSum);
						this.dataList = res.data.appletBdmIntegralGoodVos;
					}
				});
			},
			toPage(url) {
				uni.navigateTo({
					url: url,
				});
			},
			toPay(item) {
				const token = getToken();
				if (!token) {
					uni.navigateTo({
						// url: "/pages/login",
					});
				} else {
					uni.navigateTo({
						url: `/subPages/details/confirmOrder?source=integral&id=${item.id}&price=${item.price}&integral=${item.integral}`,
					});
				}
			},
			sumbit() {},
		},
	};
</script>

<style lang="less" scoped>
	* {}
    
	.Narbar {
		background: #F7F8FA;
		width: 100%;
		// height: 300px;
		display: flex;
		flex-direction: column;
		align-items: center;
		// background: url("https://fx.weisou.online/prod-api/profile/upload/2025/01/07/bg_20250107183515A018.png") no-repeat;
		// background-size: 100% 100%;

		.back {
			width: 100%;
			
		}

		.Narbar_bo {
			width: 100%;
			height: 35px;
			display: flex;
			padding: 0 28rpx;
			justify-content: space-between;
			align-items: center;
       
		
			.title {
				font-size: 18px;
				font-weight: 600;
			}
		}

		.bg {
			width: 85%;
			margin: 25px 0;
			height: 180px;
			background: url("https://fx.weisou.online/prod-api/profile/upload/2025/01/07/header_20250107183544A019.png") no-repeat;
			background-size: 100% 100%;

			.points {
				width: 100%;
				height: 50%;
				padding-left: 20px;
				padding-top: 8px;

				.pointsValue {
					padding-top: 5px;
					color: #000;
					font-size: 30px;
				}
			}

			.order {
				width: 100%;
				height: 50%;
				display: flex;
				align-items: center;
				justify-content: space-around;

				.data {
					width: 30%;
					height: 100%;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;

					image {
						width: 40px;
						height: 40px;
					}
				}
			}
		}
	}

	.recommend {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		padding: 0 20px;
	}

	.recommendi {
		width: 48%;
		margin: 20rpx 0;
		position: relative;

		.image {
			width: 100%;
			height: 335rpx;

			image {
				width: 100%;
				height: 100%;
				border-radius: 20%;
			}
		}

		.name {
			width: 100%;
			margin: 10rpx 0 10rpx;
			font-size: 28rpx;
			font-weight: 600;
			font-family: "PingFang SC";
			letter-spacing: 2rpx;
			word-break: break-all;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
		}

		.leftRight {
			display: flex;
			justify-content: space-between;

			.left {
				color: #ff4254;
				font-size: 26rpx;
			}

			.right {
				background-color: #ff4254;
				border-radius: 8rpx;
				color: #fff;
				padding: 8rpx 20rpx;
			}
		}
	}

	.box {
		width: 750rpx;
		height: 1624rpx;
		background: #F7F8FA;
		// background: #F8FCFF;
	}

	.list {
		display: flex;
		margin: 52rpx 32rpx 0;
		// border: 1rpx solid black;
		width: 686rpx;
		height: 190rpx;
		// background: #FFFFFF;
		background: #F8FCFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
	}

	.onge {
		width: 193rpx;
		height: 150rpx;
		background: #F6F6F6;
		border-radius: 12rpx 12rpx 12rpx 12rpx;

		image {
			width: 193rpx;
			height: 150rpx;
		}
	}

	.center1 {
		margin-top: 24rpx;
		width: 300rpx;
	
	
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 28rpx;
		color: #333333;
	
		font-style: normal;
		text-transform: none;
	}

	.center2 {
		margin-top: 10rpx;
		width: 323rpx;
	
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #777777;
		text-align: left;
		font-style: normal;
		text-transform: none;
	}

	.right1 {
		margin: 56rpx 0rpx 0 0;
		width: 110rpx;
		height: 36rpx;
		font-family: Douyin Sans, Douyin Sans;
		font-weight: bold;
		font-size: 30rpx;
		color: #EB5432;
		text-align: center;
		font-style: normal;
		text-transform: none;
	}

	// .right2{
	//     margin:42rpx 0 0 48rpx;
	//     width: 92rpx;
	//     height: 52rpx;
	//     background: #159DFF;
	//     border-radius: 74rpx 74rpx 74rpx 74rpx;
	//     display: flex;
	//     align-items: center;
	//     justify-content: center;
	// }
	.border {
		margin: 28rpx 0 0 8rpx;
		width: 672rpx;
		height: 0rpx;
		border: 1rpx solid #EEEEEE;
	}

	.coseBox {
		width: 686rpx;
		height: 172rpx;
		background: #FFFFFF;
		border-radius: 16rpx;
		margin: 20rpx 0 0 32rpx;
	}

	.coseFle {
		display: flex;
		justify-content: space-between;
		padding: 23rpx 0 0 18rpx;

	}

	.cose {
		width: 52rpx;
		height: 36rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 26rpx;
		color: #333333;
		text-align: center;
		font-style: normal;
		text-transform: none;
	}

	.coseDet {
		width: 110rpx;
		height: 36rpx;
		font-family: Douyin Sans, Douyin Sans;
		font-weight: bold;
		font-size: 30rpx;
		color: #EB5432;
		text-align: center;
		font-style: normal;
		text-transform: none;
	}

	.coseImg {
		margin-left: 390rpx;
		width: 44.69rpx;
		width: 40rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.cose1 {
		width: 104rpx;
		height: 36rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 26rpx;
		color: #333333;
		text-align: center;
		font-style: normal;
		text-transform: none;
	}

	.coseDet1 {
		width: 104rpx;
		height: 36rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 26rpx;
		color: #333333;
		text-align: center;
		font-style: normal;
		text-transform: none;
	}

	.buttonClick {
		// position: fixed;
		// bottom: 0rpx;
		position: fixed;
		bottom: 0;
		margin-bottom: calc(24rpx + env(safe-area-inset-bottom));
		// border:1rpx solid black;
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 750rpx;
		height: 94rpx;
		background: #FFFFFF;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.buttonPay {
		display: flex;
		justify-content: space-around;
		align-items: center;
	}

	.pay1 {
		margin: 0 38rpx 0 46rpx;
		width: 120rpx;
		height: 40rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 28rpx;
		color: #000000;
		text-align: center;
		font-style: normal;
		text-transform: none;
	}

	.pay2 {
		margin: 0 38rpx 0 46rpx;
		width: 110rpx;
		height: 36rpx;
		font-family: Douyin Sans, Douyin Sans;
		font-weight: bold;
		font-size: 30rpx;
		color: #EB5432;
		text-align: center;
		font-style: normal;
		text-transform: none;
	}

	.payPre {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 374rpx;
		height: 94rpx;
		background: #159DFF;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		// margin-right: 106rpx;
	}

	.button {

		width: 160rpx;
		height: 44rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 32rpx;
		color: #FFFFFF;
		text-align: center;
		font-style: normal;
		text-transform: none;
	}
</style>